import FriendListData from "../../model/item/FriendListData";

let app = getApp();
let globalStore = app.globalData.globalStore;

Page({
  data: {
    items:[]
  },
  onLoad:function(){

    // 绑定实时刷新回调
    globalStore.addFriendListener(this.onFriendUpdate.bind(this));
    // 使用初始化的数据更新列表
    this.onFriendUpdate(globalStore.friendList);
  },
  onFriendUpdate(friends){
    const items = friends.map((v)=>{
      const data =  new FriendListData();
      data.id = v.auid;
      data.avatar = v.avatar;
      data.name = v.name;
      data.body = '';
      data.online = v.online;
      data.sign = v.sign;

      return data;
    });

    this.setData({
      items : items
    });
  }
})
